
package TransportesMarroquin;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
import java.io.IOException;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import net.sf.jxls.exception.ParsePropertyException;
import net.sf.jxls.report.ReportManager;
import net.sf.jxls.report.ReportManagerImpl;
import net.sf.jxls.transformer.XLSTransformer;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;


public class Archivo {
    
    public static void Abrir(String file){
                     
                        
            try
            {
               Process p = Runtime.getRuntime().exec ("rundll32 SHELL32.DLL,ShellExec_RunDLL "+file);
            }
            catch (Exception e)
            {
               System.out.println("Error al abrir el archivo " + file + "\n" + e.getMessage());
            }
       
       
   
    }
    public static String TipoA (String plantilla,String nombre, String apellido){
         String file = null; 
        try
        {
                     // coneccion a la base de datos
        MysqlDataSource datasource= new MysqlDataSource();
        datasource.setUser("root");
        datasource.setPassword("");
        datasource.setDatabaseName("practicasp8");
        datasource.setServerName("localhost");
        Connection conexion;
        conexion = (Connection) datasource.getConnection();
                    Map beans = new HashMap();
                    ReportManager rm = new ReportManagerImpl( conexion, beans );
                    beans.put("rm", rm);
                    beans.put("nombre",nombre);
                    beans.put("apellido",apellido);
                    XLSTransformer transformer = new XLSTransformer();
                    transformer.transformXLS(System.getProperty("user.dir")+"\\src\\Plantillas\\"+plantilla+".xls", beans, System.getProperty("user.dir")+"\\src\\DocumentosExcel\\"+plantilla+".xls");
                  
                    file = (System.getProperty("user.dir")+"\\src\\DocumentosExcel\\"+plantilla+".xls");
            }
        catch (ParsePropertyException ex) {
            java.util.logging.Logger.getLogger(Piloto.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            java.util.logging.Logger.getLogger(Piloto.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InvalidFormatException ex) {
            java.util.logging.Logger.getLogger(Piloto.class.getName()).log(Level.SEVERE, null, ex);
        }        catch (SQLException ex)
        {
            java.util.logging.Logger.getLogger(Piloto.class.getName()).log(Level.SEVERE, null, ex);
        }
                
           return file;
           
    }
    public static String TipoB (String plantilla,String placa){
          String file = null; 
        try
        {
                     // coneccion a la base de datos
        MysqlDataSource datasource= new MysqlDataSource();
        datasource.setUser("root");
        datasource.setPassword("");
        datasource.setDatabaseName("practicasp8");
        datasource.setServerName("localhost");
        Connection conexion;
        conexion = (Connection) datasource.getConnection();
                    Map beans = new HashMap();
                    ReportManager rm = new ReportManagerImpl( conexion, beans );
                    beans.put("rm", rm);
                    beans.put("placa",placa);
                    XLSTransformer transformer = new XLSTransformer();
                     transformer.transformXLS(System.getProperty("user.dir")+"\\src\\Plantillas\\"+plantilla+".xls", beans, System.getProperty("user.dir")+"\\src\\DocumentosExcel\\"+plantilla+".xls");
                  
                    file = (System.getProperty("user.dir")+"\\src\\DocumentosExcel\\"+plantilla+".xls");
    
       
        }
        catch (ParsePropertyException ex) {
            java.util.logging.Logger.getLogger(Piloto.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            java.util.logging.Logger.getLogger(Piloto.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InvalidFormatException ex) {
            java.util.logging.Logger.getLogger(Piloto.class.getName()).log(Level.SEVERE, null, ex);
        }        catch (SQLException ex)
        {
            java.util.logging.Logger.getLogger(Piloto.class.getName()).log(Level.SEVERE, null, ex);
        }
   
                
           return file;
        
    }
    public static String TipoC (String plantilla,String var,boolean gasto){
          String file = null; 
        try
        {
                     // coneccion a la base de datos
        MysqlDataSource datasource= new MysqlDataSource();
        datasource.setUser("root");
        datasource.setPassword("");
        datasource.setDatabaseName("practicasp8");
        datasource.setServerName("localhost");
        Connection conexion;
        conexion = (Connection) datasource.getConnection();
                    Map beans = new HashMap();
                    SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
                    ReportManager rm = new ReportManagerImpl( conexion, beans );
                    beans.put("rm", rm);
                    if(gasto)
                    beans.put("placa",var);  
                    beans.put("fecha", dateFormat);
                   
                    
                    XLSTransformer transformer = new XLSTransformer();
                     transformer.transformXLS(System.getProperty("user.dir")+"\\src\\Plantillas\\"+plantilla+".xls", beans, System.getProperty("user.dir")+"\\src\\DocumentosExcel\\"+plantilla+".xls");
                  
                    file = (System.getProperty("user.dir")+"\\src\\DocumentosExcel\\"+plantilla+".xls");
    
       
        }
        catch (ParsePropertyException ex) {
            java.util.logging.Logger.getLogger(Piloto.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            java.util.logging.Logger.getLogger(Piloto.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InvalidFormatException ex) {
            java.util.logging.Logger.getLogger(Piloto.class.getName()).log(Level.SEVERE, null, ex);
        }        catch (SQLException ex)
        {
            java.util.logging.Logger.getLogger(Piloto.class.getName()).log(Level.SEVERE, null, ex);
        }
   
                
           return file;
        
    }
     public static String TipoD (String plantilla,String tipo,int codigo){
          String file = null; 
        try
        {
                     // coneccion a la base de datos
        MysqlDataSource datasource= new MysqlDataSource();
        datasource.setUser("root");
        datasource.setPassword("");
        datasource.setDatabaseName("practicasp8");
        datasource.setServerName("localhost");
        Connection conexion;
        conexion = (Connection) datasource.getConnection();
                    Map beans = new HashMap();
                    SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
                    ReportManager rm = new ReportManagerImpl( conexion, beans );
                    beans.put("rm", rm);
                    beans.put("tipo",tipo);
                    beans.put("codigo", codigo);
                     beans.put("fecha", dateFormat);
                    XLSTransformer transformer = new XLSTransformer();
                     transformer.transformXLS(System.getProperty("user.dir")+"\\src\\Plantillas\\"+plantilla+".xls", beans, System.getProperty("user.dir")+"\\src\\DocumentosExcel\\"+plantilla+".xls");
                  
                    file = (System.getProperty("user.dir")+"\\src\\DocumentosExcel\\"+plantilla+".xls");
    
       
        }
        catch (ParsePropertyException ex) {
            java.util.logging.Logger.getLogger(Piloto.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            java.util.logging.Logger.getLogger(Piloto.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InvalidFormatException ex) {
            java.util.logging.Logger.getLogger(Piloto.class.getName()).log(Level.SEVERE, null, ex);
        }        catch (SQLException ex)
        {
            java.util.logging.Logger.getLogger(Piloto.class.getName()).log(Level.SEVERE, null, ex);
        }
   
                
           return file;
        
    }
    
    
}
